<?php
/**
 * Created by PhpStorm.
 * User: luojinyi
 * Date: 2017/11/28
 * Time: 下午2:54
 */

namespace App\Models;


use App\Traits\Setting;
use Illuminate\Support\Facades\Log;

class Attachment extends BaseModel
{
    /**
     * 与模型关联的数据表
     *
     * @var string
     */
    protected $table = 'attachment';

    /**
     * 主键
     * @var string
     */
    protected $primaryKey = 'id';


    /**
     * 需要被转换成日期的属性。
     *
     * @var array
     */
    protected $dates = ['created_at', 'updated_at'];

    /**
     * @var array
     */
    protected $hidden = ['created_at', 'updated_at'];

    /**
     * 字段别名 用于验证转换
     * @var array
     */
    public $attrAlias = [
        "id" => '附件id',
        "object_key" => '对象key',
        "file_name" => '文件名'
    ];

    /**
     * @var array
     */
    protected $appends = ['full_path'];

    /**
     * @return bool
     */
    public function getFullPathAttribute()
    {
        //获取参数
        if( $config = Setting::getStaticSettingCache(OSS_KEY) ){
            return $config['Domain'].$this->object_key;
        }

        Log::error('获取oss参数错误');
        return  false;
    }
}
